package chapters
{
	import com.greensock.easing.Linear;
	
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import flashx.textLayout.formats.TextAlign;
	
	import globals.$rootScene;
	
	import slices.BlankTime;
	import slices.TimeSlice;
	import globals.$athena;
	import globals.$root;
	import org.musince.util.TextFieldUtil;
	import slices.FunctionSlice;
	import slices.TweenSlice;
	
	public class Whereas extends TimeSlice
	{
		private var _slot:Sprite; 
		
		public function Whereas()
		{
			super();
		}
		
		override public function onStart():void {
			var texts:Array = ["时间永远都在无情的流逝 ", "无论如何挣扎", "生命的尽头", "终究..."];
			var ys:Array = [140, 255, 372, 490];
			var froms:Array = [377+20, 675-20, 469+20, 583];
			var tos:Array = [377, 675, 469, 583];
			var pauses:Array = [1000, 1000, 1000, 3000];
			var prev:TimeSlice = new BlankTime(0); var next:TimeSlice;
			var tf:TextField;
			_slot = new Sprite();
			
			$athena.addTimeSlice(prev);
			
			for (var i:int = 0; i < 4; i++) {
				tf = TextFieldUtil.getMonoText();
				tf.x = froms[i];
				tf.text = texts[i];
				tf.y = ys[i];
				tf.alpha = 0;
				_slot.addChild(tf);
				next = new TweenSlice(tf, 1, {x:tos[i], alpha:1, ease:Linear.easeNone});				
				prev.appendNext(next);
				prev = new BlankTime(pauses[i]);
				next.appendNext(prev);
			}
			$rootScene.addChild(_slot);
			prev.appendNext(new FunctionSlice(onTextOver));
		}
		
		private function onTextOver():void {
			var ts:TweenSlice = new TweenSlice(_slot, 3, {alpha:0});
			ts.appendNext(new FunctionSlice(onSlotHide));
			$athena.addTimeSlice(ts);
		}
		
		private function onSlotHide():void {
			$rootScene.removeChild(_slot);
			isEnd = true;
		}
	}
}